package com.example.rabbitmq.config;

import com.example.rabbitmq.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQDelayConfig {
    @Bean("delayExchange")
    public Exchange delayExchange() {
        //默认持久化是true的，如果没有显示指定的话
        //可以通过durable(false)的方式来显示指定不需要持久化
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE).durable(true).delayed().build();
    }
    @Bean("delayQueue")
    public Queue delayQueue() {
        //需要显示指定是否需要持久化
        return QueueBuilder.durable(Constants.DELAY_QUEUE).build();
    }
    @Bean("delayBinding")
    public Binding delayBinding(@Qualifier("delayExchange") Exchange exchange, @Qualifier("delayQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("delay").noargs();
    }
}
